package com.ruoyi.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.entity.JrTemplates;
import com.ruoyi.mapper.TemplatesMapper;
import com.ruoyi.service.TemplatesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TemplatesServiceImpl implements TemplatesService {
    @Autowired
    private TemplatesMapper templatesMapper;

    @Override
    public List<JrTemplates> getRecentTemplates() {
        return templatesMapper.selectRecentTemplates();
    }

    @Override
    public boolean updateById(JrTemplates template) {
        template.setUpdateTime(new Date());
        return templatesMapper.updateById(template) > 0;
    }
    @Override
    public int deleteById(Long id) {
        return templatesMapper.deleteById(id);
    }

    @Override
    public Long saveTemplate(JrTemplates templates) {
        Date now = new Date();

        templates.setCreateTime(now);
        templates.setUpdateTime(now);
        templates.setUsageCount(0); // 初始使用量为0
        templatesMapper.insertJrTemplates(templates);
        return templates.getId();
    }

    @Override
    public JrTemplates getById(Long id) {
        return templatesMapper.selectById(id);
    }

    @Override
    public JrTemplates getByName(String name) {
        return templatesMapper.selectByName(name);
    }

    @Override
    public List<JrTemplates> selectTemplateList(JrTemplates templates) {
        return templatesMapper.selectTemplateList(templates);
    }
}
